{include file="admin/common/header" /}
<body class="pear-container">
<div class="layui-card">
    <div class="layui-card-body">
        <table id="admin_table" lay-filter="admin_table"></table>
    </div>
</div>
<script type="text/html" id="add_toolbar">
    <button class="pear-btn pear-btn-primary pear-btn-md {php}if(!check_auth(__url('/app/huiblog/cate/add'))){ echo 'layui-hide';} {/php}"
            data-open="/app/huiblog/cate/add"
            data-title="添加分类" data-reload="2">
        <i class="layui-icon layui-icon-add-1"></i>
        新增
    </button>
</script>

<script type="text/html" id="switchTpl">
    <input type="checkbox" name="status" value="{{d.status}}" lay-skin="switch" lay-filter="switchStatus"
           data-href="/app/huiblog/cate/status?id={{d.id}}&field=status" lay-text="显示|不显示" {{ d.status== 1 ? 'checked' : '' }}>
</script>
<script type="text/html" id="barDemo">
    <button class="pear-btn pear-btn-zise pear-btn-sm" title="添加下级"
            data-open="/app/huiblog/cate/add?id={{d.id}}"
            data-title="添加下级" data-reload="2">
        <i class="layui-icon layui-icon-add-1"></i>
    </button>
    <button class="pear-btn pear-btn-primary pear-btn-sm" title="编辑"
            data-open="/app/huiblog/cate/edit?id={{d.id}}"
            data-title="编辑" data-reload="2">
        <i class="layui-icon layui-icon-edit"></i>
    </button>
    <button class="pear-btn pear-btn-danger pear-btn-sm" title="删除"
            data-delete="/app/huiblog/cate/delete?id={{d.id}}"
            data-title="您确定要删除吗？" data-reload="2">
        <i class="layui-icon layui-icon-delete"></i>
    </button>
</script>
{include file="admin/common/footer" /}
<script>
  layui.use(['table', 'jquery', 'treetable'], function () {
    var $ = layui.jquery;
    var table = layui.table;
    var treetable = layui.treetable;

    // 渲染表格
    layer.load(2);
    treetable.render({
      toolbar: '#add_toolbar',
      treeColIndex: 2,
      treeSpid: 0,
      treeIdName: 'id',
      treePidName: 'pid',
      elem: '#admin_table',
      method: 'get',
      url: "/app/huiblog/cate/index",
      page: false,
      cols: [[
        {field: 'id', width: 100, title: 'id', align: 'center'},
        {field: 'sort', width: 130, title: '排序', align: 'center'},
        {field: 'title', minWidth: 200, title: '分类名称'},
        {field: 'pid', width: 100, title: '父级ID', align: 'center'},
        {field: 'status', title: '状态', width: 120, templet: '#switchTpl', align: 'center'},
        {
          width: 200,
          title: '操作',
          templet: '#barDemo',
          align: 'center',
        }
      ]],
      done: function () {
        layer.closeAll('loading');
      }
    });

    //监听行工具事件
    table.on('toolbar(admin_table)', function (obj) {
      console.log(obj);
      if (obj.event === 'refresh') {
        table.reload('testReload');
      }
    });

  });
</script>
</body>
</html>
